/**
 * Copyright 2009 Jesse Brown (jbrown@fluentv.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package com.fluentv.games.netblocks;

import java.util.UUID;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;

/**
 * Main entrypoint for the Netblocks game. Basically just provides an initial screen and not much else.
 *  
 * @author Jesse Brown (jbrown@fluentv.com)
 */
public class Netblocks extends Activity {

  private static final String LOG_TAG = Netblocks.class.getName();
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Don't bother with a title bar.	
    setContentView(R.layout.main);		
 
    // Common buttons and checkboxes.
    final CheckBox soundEffectsCheckbox = 
      (CheckBox) findViewById(R.id.checkbox_sound_effects);
    
    //Hook up our buttons
    final Button startGameButton = (Button) findViewById(R.id.button_start_game);
    startGameButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {		
        Log.i(LOG_TAG, "Starting new game from main page");

        // Create a new game ID.
        String gameId = UUID.randomUUID().toString();
        
        Intent intent = new Intent();
        intent.setClass(Netblocks.this, PlayingActivity.class);
        intent.putExtra(PlayingActivity.GAME_ID_KEY, gameId);
        intent.putExtra(PlayingActivity.MUTED_KEY, !soundEffectsCheckbox.isChecked());
        startActivityIfNeeded(intent, -1);
      }
    });
    
    final Button resumeGameButton = (Button) findViewById(R.id.button_resume_game);
    resumeGameButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {          
        Log.i(LOG_TAG, "Resuming existing game");

        Intent intent = new Intent();
        intent.setClass(Netblocks.this, PlayingActivity.class);
        intent.putExtra(PlayingActivity.MUTED_KEY, !soundEffectsCheckbox.isChecked());
        startActivityIfNeeded(intent, -1);                               
      }
    });
        
    final Button howToPlayButton = (Button) findViewById(R.id.button_how_to_play);
    howToPlayButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Log.i(LOG_TAG, "Showing how-to-play screen");

        Intent intent = new Intent();
        intent.setClass(Netblocks.this, HowToPlayActivity.class);
        startActivityIfNeeded(intent, 0);      	
      }
    });
  }     
}